<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h1>今天天气{{weather}}</h1>
      <button @click="isHot = !isHot">切换天气</button>
    </div>

    <script src="./vue.js"></script>

    <script>
      const vm = new Vue({
        el: '#app',
        data: {
          isHot: true,
          weather: '',
        },
        // computed: {
        //   weather() {
        //     return this.isHot ? '炎热' : '凉爽'
        //   }, // 计算属性，依赖于data中的数据
        // },
        watch: {
          isHot: {
            immediate: true,
            handler(newVal) {
              this.weather = newVal ? '炎热' : '凉爽'
            },
          },
        },
      })
    </script>
  </body>
</html>
